package com.qifenqian.turbot.deprecated.unused

import android.content.Context
import android.support.v4.view.PagerAdapter
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup

/**
 * @author H
 * @createDate 2018/6/25 10:37
 * @reference
 * @updateDate
 * @description viewPager适配器base
 * @detail
 * @since
 */
abstract class BaseCirclePagerAdapter<T> : PagerAdapter {

    protected var mContext: Context
    private var mLayoutRes: Int? = 0
    private var mList: List<T>? = null

    constructor(context: Context, tList: List<T>) {
        mContext = context
        mList = tList
    }

    constructor(context: Context, layoutRes: Int, list: List<T>) {
        mContext = context
        mLayoutRes = layoutRes
        mList = list
    }

    override fun getCount(): Int {
        return mList!!.size
    }

    override fun instantiateItem(container: ViewGroup, position: Int): Any {
        val view: View = if (mLayoutRes != 0) {
            LayoutInflater.from(mContext).inflate(mLayoutRes!!, null)
        } else {
            createView(mContext)
        }
        val parent = view.parent as ViewGroup
        parent.removeAllViews()
        if (mList != null && !mList!!.isEmpty()) {
            val t = mList!![position]
            setItemView(view, t)
        }
        container.addView(view)
        return view
    }

    protected abstract fun createView(context: Context): View

    protected abstract fun setItemView(view: View, t: T)

    override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
        container.removeView(`object` as View)
    }

    override fun isViewFromObject(view: View, `object`: Any): Boolean {
        return view === `object`
    }

}
